/*
 * @Copyright: 2017 www.yyfax.com Inc. All rights reserved.
 */
package com.yyfax.pay.third.facade.lianlian;

import static com.yyfax.framework.yyfax.enums.RspCodeEnum.COMMON_ERROR_UNKNOWN_EXCEPTION;
import static com.yyfax.pay.common.enums.PayRspCodeEnum.PAY_CODE_BANK_NOT_SUPPORT;
import static com.yyfax.pay.common.enums.PayRspCodeEnum.PAY_CODE_CARD_EXCEPTION;
import static com.yyfax.pay.common.enums.PayRspCodeEnum.PAY_CODE_CARD_TYPE_NOT_SUPPORT;
import static com.yyfax.pay.common.enums.PayRspCodeEnum.PAY_CODE_QUERY_CARD_BIN_ERROR;
import static com.yyfax.pay.common.enums.PayRspCodeEnum.PAY_CODE_QUERY_ORDER_FAIL;

import java.util.HashMap;
import java.util.Map;

import com.yyfax.pay.third.model.to.yyfax.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yyfax.commons.json.JacksonUtil;
import com.yyfax.commons.lang.DateUtil;
import com.yyfax.commons.lang.Md5Util;
import com.yyfax.commons.lang.NumberUtil;
import com.yyfax.commons.lang.RSAUtil;
import com.yyfax.framework.model.Content;
import com.yyfax.framework.model.Params;
import com.yyfax.framework.yyfax.enums.YesNoEnum;
import com.yyfax.pay.common.enums.PayModeEnum;
import com.yyfax.pay.common.enums.PayRspCodeEnum;
import com.yyfax.pay.common.enums.PayTypeEnum;
import com.yyfax.pay.common.enums.PaymentEnum;
import com.yyfax.pay.common.exception.YYPayException;
import com.yyfax.pay.common.util.LianlianSignUtil;
import com.yyfax.pay.config.data.service.BankConfigService;
import com.yyfax.pay.config.data.service.MerchantPaymentService;
import com.yyfax.pay.config.model.po.BankConfigPO;
import com.yyfax.pay.config.model.po.MerchantPaymentPO;
import com.yyfax.pay.third.model.to.lianlian.LianlianExt;
import com.yyfax.pay.third.model.to.lianlian.PayoutOrderLianlianContent;
import com.yyfax.pay.third.model.to.lianlian.PayoutOrderLianlianParams;
import com.yyfax.pay.third.model.to.lianlian.PayoutOrderLianlianReq;
import com.yyfax.pay.third.model.to.lianlian.QueryCardBinLianLianContent;
import com.yyfax.pay.third.model.to.lianlian.QueryCardBinLianLianParams;
import com.yyfax.pay.third.model.to.lianlian.QueryCardBinLianLianReq;
import com.yyfax.pay.third.model.to.lianlian.QueryPayOrderLianlianContent;
import com.yyfax.pay.third.model.to.lianlian.QueryPayOrderLianlianParams;
import com.yyfax.pay.third.model.to.lianlian.QueryPayOrderLianlianReq;
import com.yyfax.pay.third.model.to.lianlian.QueryPayOutOrderLianlianContent;
import com.yyfax.pay.third.model.to.lianlian.QueryPayOutOrderLianlianParams;
import com.yyfax.pay.third.model.to.lianlian.QueryPayOutOrderLianlianReq;
import com.yyfax.pay.third.service.TransformService;

/**
 * 连连参数转换器
 *
 * @author jiangmy
 * @date 2017-04-11 18:51:54
 * @since v1.0.0
 */
@Service("lianlianTransformService")
public class LianlianTransformService implements TransformService {

	private Logger logger = LoggerFactory.getLogger(LianlianTransformService.class);

	@Autowired
	private BankConfigService bankConfigService;

	@Autowired
	private MerchantPaymentService merchantPaymentService;

	@Override
	public <P extends Params> P transformQueryPayOrderParams(QueryPayOrderYYParams req) throws Exception{
		QueryPayOrderLianlianParams queryPayOrderLianlianParams = new QueryPayOrderLianlianParams();
		Map<String, String> params = new HashMap<>();
		// 请求参数
//		try {
			queryPayOrderLianlianParams = getParamsPay(req);
//		} catch (Throwable t) {
//			t.printStackTrace();
//		}
		//		String url = StringHelper.format(LianLianPayVariable.CHECK_URL.getValue(), configureProvider);	// 请求地址

		logger.info("-----------查询友金所充值订单[{}]，请求参数={}", req.getPayOrderId(), params);

		return (P) queryPayOrderLianlianParams;
	}

	/**
	 * 生成支付结果查询接口请求参数
	 *
	 * @param req
	 * @return
	 * @throws Throwable
	 */
	private QueryPayOrderLianlianParams getParamsPay(QueryPayOrderYYParams req) throws Exception {
		QueryPayOrderLianlianParams queryPayOrderLianlianParams = new QueryPayOrderLianlianParams();
		QueryPayOrderLianlianReq queryPayOrderLianlianReq = new QueryPayOrderLianlianReq();

		LianlianExt lianlianExt = getMerchantInfo(req.getMerchantCode(), PayTypeEnum.PAY, PayModeEnum.AUTH_PAY);
		// 连连商户号
		String oid_partner = lianlianExt.getOidPartner();
		String sign_type = lianlianExt.getSignType();        // 签名方式
		String sign_key = "MD5".equals(sign_type) ? lianlianExt.getMd5Key() : lianlianExt.getPrivateRsaKey();

		String dateStr = DateUtil.date2Str(DateUtil.str2DateTime(req.getOrderTime()), "yyyyMMddHHmmss");
		String no_order = req.getPayOrderId();        // 商户唯一订单号
		String dt_order = dateStr;                // 商户订单时间

		Map<String, String> params = new HashMap<String, String>();
		queryPayOrderLianlianReq.setOid_partner(oid_partner);
		queryPayOrderLianlianReq.setSign_type(sign_type);
		queryPayOrderLianlianReq.setNo_order(no_order);
		queryPayOrderLianlianReq.setDt_order(dt_order);

		// 签名
		String result = "";
		String sb = LianlianSignUtil.getSignStr(params);
		if ("MD5".equals(sign_type)) {
			// Md5签名
			sb += "&key=" + sign_key;
			result = Md5Util.md5(sb).toLowerCase();
		} else {
			// RSA加密
			result = RSAUtil.sign(sign_key, sb);
		}
		queryPayOrderLianlianReq.setSign(StringUtils.isBlank(result) ? "" : result);

		queryPayOrderLianlianParams.setUrl(lianlianExt.getCheckUrl());
		queryPayOrderLianlianParams.setQueryPayOrderLianlianReq(queryPayOrderLianlianReq);

		return queryPayOrderLianlianParams;
	}


	@Override
	public <C extends Content> QueryPayOrderYYContent transformQueryPayOrderContent(C rsp) {
		QueryPayOrderYYContent queryPayOrderYYContent = new QueryPayOrderYYContent();

		QueryPayOrderLianlianContent queryPayOrderLianlianContent = (QueryPayOrderLianlianContent) rsp;

		if (queryPayOrderLianlianContent == null) {
			queryPayOrderYYContent.setResultCode(PayRspCodeEnum.COMMON_ERR0R_NET_ERROR.getValue());
			return queryPayOrderYYContent;
		}

		// 支付结果
		String result_pay = queryPayOrderLianlianContent.getResult_pay();

		if (result_pay != null) {
			switch (result_pay) {
			case "SUCCESS":
				queryPayOrderYYContent.setResultCode(PayRspCodeEnum.SUCCESS.getValue());
				break;
			case "FAILURE":
				queryPayOrderYYContent.setResultCode(PAY_CODE_QUERY_ORDER_FAIL.getValue());
				break;
			default:
				queryPayOrderYYContent.setResultCode(PAY_CODE_QUERY_ORDER_FAIL.getValue());
				break;
			}
			queryPayOrderYYContent.setOrderId(queryPayOrderLianlianContent.getNo_order());

			double moneyOrder = Double.valueOf(queryPayOrderLianlianContent.getMoney_order());
			queryPayOrderYYContent.setAmount(Long.valueOf(NumberUtil.yuan2fen(moneyOrder)).intValue());
			queryPayOrderYYContent.setResultMsg(queryPayOrderLianlianContent.getMemo());
			queryPayOrderYYContent.setSerialNo(queryPayOrderLianlianContent.getOid_paybill());
		} else {
			queryPayOrderYYContent.setResultCode(PayRspCodeEnum.PAY_CODE_QUERY_ORDER_FAIL.getValue());
			queryPayOrderYYContent.setResultMsg(queryPayOrderLianlianContent.getRet_msg());
		}
		return queryPayOrderYYContent;
	}

	@Override
	public <P extends Params> P transformAuthenticationParams(AuthenticationYYParams req) {
		return null;
	}

	@Override
	public <C extends Content> AuthenticationYYContent transformAuthenticationContent(C rsp) {
		return null;
	}

	@Override
	public <P extends Params> P transformBatchPayoutOrderCheckParams(QueryBatchPayoutOrderCheckYYParams req) {
		return null;
	}

	@Override
	public <C extends Content> QueryBatchPayoutOrderCheckYYContent transformBatchPayoutOrderCheckContent(C rsp) {
		return null;
	}

	@Override
	public <P extends Params> P transformBatchPayoutOrderParams(PayoutBatchOrderYYParams req) {
		return null;
	}

	@Override
	public <C extends Content> PayoutBatchOrderYYContent transformBatchPayoutOrderContent(C rsp) {
		return null;
	}

	@Override
	public <P extends Params> P transformPayOrdeParams(PayOrderYYParams req) {
		return null;
	}

	@Override
	public <C extends Content> PayOrderYYContent transformPayOrdeContent(C rsp) {
		return null;
	}

	@Override
	public <P extends Params> P transformPayoutOrderParams(PayoutOrderYYParams rsp) throws Exception{

		PayoutOrderLianlianParams payoutOrderLianlianParams = new PayoutOrderLianlianParams();
		PayoutOrderLianlianReq payoutOrderLianlianReq = new PayoutOrderLianlianReq();

		LianlianExt lianlianExt = getMerchantInfo(rsp.getMerchantCode(), PayTypeEnum.PAY_OUT, PayModeEnum.AUTH_PAY);

//		String notify_url = configureProvider.format(LianLianPayVariable.NOTIFY_URL_DF);
		// 客户姓名
		payoutOrderLianlianReq.setAcct_name(rsp.getPayeeName());
//		repayParam.put("acct_name", repayEntity.accountName.trim());
		// 客户卡号
		payoutOrderLianlianReq.setCard_no(rsp.getPayeeCardNo());
//		repayParam.put("card_no", StringHelper.decode(repayEntity.F03));
		// 代付金额
		String moneyOrder = NumberUtil.fen2yuan(String.valueOf(rsp.getAmount()));
		payoutOrderLianlianReq.setMoney_order(moneyOrder);
//		repayParam.put("money_order", String.valueOf(repayEntity.F05.doubleValue()));
		// 异步通知地址
		payoutOrderLianlianReq.setNotify_url(lianlianExt.getNotifyUrl());
//		repayParam.put("notify_url", notify_url);
		payoutOrderLianlianReq.setNo_order(rsp.getPayoutOrderId());
//		no_order = this.getTransID(repayEntity.F01, repayEntity.F04);
//		repayParam.put("no_order", no_order);
		// 订单时间
		String orderTime = DateUtil.date2Str(DateUtil.str2DateTime(rsp.getPayOrderTime()), "yyyyMMddHHmmss");
		payoutOrderLianlianReq.setDt_order(orderTime);
//		repayParam.put("dt_order", DateParser.format(repayEntity.F04, "yyyyMMddHHmmss"));
		// 代付订单信息
		payoutOrderLianlianReq.setInfo_order("友金所代付给用户"+rsp.getUserId());
//		repayParam.put("info_order", "友金所代付给用户" + repayEntity.accountName.trim());

		// 对公对私标志 0：对私，1：对公
		payoutOrderLianlianReq.setFlag_card("0");
//		repayParam.put("flag_card", FLAG_CARD);
		// 大额行号不需要再传
//		repayParam.put("prcptcd", StringHelper.isEmpty(repayEntity.prcptcd) ? "" : repayEntity.prcptcd.trim());

		payoutOrderLianlianReq.setApi_version(lianlianExt.getVersion());
		payoutOrderLianlianReq.setOid_partner(lianlianExt.getOidPartner());

		String signType = lianlianExt.getSignType();
		payoutOrderLianlianReq.setSign_type(signType);

		// 创建签名
		//		this.createSendOrderSign(repayParam, configureProvider);
		String signKey = "MD5".equals(signType) ? lianlianExt.getMd5Key() : lianlianExt.getPrivateRsaKey();
		// 签名
		Map<String, String> params = LianlianSignUtil.objectToMap(payoutOrderLianlianReq);
		String result = createSendSign(params, signKey, signType);
		payoutOrderLianlianReq.setSign(StringUtils.isBlank(result) ? "" : result);

		payoutOrderLianlianReq.setBank_code("");
		payoutOrderLianlianReq.setBrabank_name("");
		payoutOrderLianlianReq.setPlatform("");
		payoutOrderLianlianReq.setPrcptcd("");
		payoutOrderLianlianReq.setProvince_code("");
		payoutOrderLianlianReq.setCity_code("");

		payoutOrderLianlianParams.setUrl(lianlianExt.getPayoutUrl());
		payoutOrderLianlianParams.setPayoutOrderLianlianReq(payoutOrderLianlianReq);

		return (P)payoutOrderLianlianParams;
	}

	@Override
	public <C extends Content> PayoutOrderYYContent transformPayoutOrderContent(C rsp) {
		PayoutOrderYYContent payoutOrderYYContent = new PayoutOrderYYContent();

		PayoutOrderLianlianContent content = (PayoutOrderLianlianContent) rsp;

		if (content == null) {
			payoutOrderYYContent.setResultCode(PayRspCodeEnum.COMMON_ERR0R_NET_ERROR.getValue());
			return payoutOrderYYContent;
		}

		// 支付结果
		String retCode = content.getRet_code();
		String retMsg = content.getRet_msg();

		if (retCode.equals("0000")) {
			payoutOrderYYContent.setResultCode(PayRspCodeEnum.SUCCESS.getValue());
			payoutOrderYYContent.setResultMsg(retMsg);
		} else {
			payoutOrderYYContent.setResultCode(COMMON_ERROR_UNKNOWN_EXCEPTION.getValue());
			payoutOrderYYContent.setResultMsg(retMsg);
		}

		return payoutOrderYYContent;
	}

	@Override
	public <P extends Params> P transformQueryBatchPayoutOrderParams(QueryBatchPayoutOrderYYParams rsp) {
		return null;
	}

	@Override
	public <C extends Content> QueryBatchPayoutOrderYYContent transformQueryBatchPayoutOrderContent(C req) {
		return null;
	}

	@Override
	public <P extends Params> P transformSendAuthenticationVerifyCodeParams(SendAuthenticationVerifyCodeYYParams rsp) {
		return null;
	}

	@Override
	public <C extends Content> SendAuthenticationVerifyCodeYYContent transformSendAuthenticationVerifyCodeContent(C req) {
		return null;
	}

	@Override
	public <P extends Params> P transformSendVerifyCodeParams(SendVerifyCodeYYParams rsp) {
		return null;
	}

	@Override
	public <C extends Content> SendVerifyCodeYYContent transformSendVerifyCodeContent(C req) {
		return null;
	}

	@Override
	public <P> P transformQueryCardBinParams(QueryCardBinParams rsp) {
		QueryCardBinLianLianParams queryCardBinLianLianParams = new QueryCardBinLianLianParams();
		QueryCardBinLianLianReq queryCardBinLianLianReq = new QueryCardBinLianLianReq();
		try{
			queryCardBinLianLianReq.setCard_no(rsp.getCardNo());

			LianlianExt lianlianExt = getMerchantInfo(rsp.getMerchantCode(), PayTypeEnum.CARD_BIN, PayModeEnum.AUTH_PAY);

			String oidPartner = lianlianExt.getOidPartner();
			queryCardBinLianLianReq.setOid_partner(oidPartner);

			String flagAmtLimit = lianlianExt.getFlagAmtLimit();
			queryCardBinLianLianReq.setFlag_amt_limit(flagAmtLimit);

//			String sign_type = "MD5";        // 签名方式
//			String sign_key = "";
			String sign_type = lianlianExt.getSignType();        // 签名方式
			queryCardBinLianLianReq.setSign_type(sign_type);

			String sign_key = "MD5".equals(sign_type) ? lianlianExt.getMd5Key() : lianlianExt.getPrivateRsaKey();

			// 签名
			Map<String, String> params = LianlianSignUtil.objectToMap(queryCardBinLianLianReq);
			String result = createSendSign(params, sign_key, sign_type);

			queryCardBinLianLianReq.setSign(StringUtils.isBlank(result) ? "" : result.toLowerCase());

			queryCardBinLianLianParams.setQueryCardBinLianLianReq(queryCardBinLianLianReq);
			queryCardBinLianLianParams.setUrl(lianlianExt.getCardBinUrl());
		} catch (Exception e){
			logger.error("{}", e);
		}

		return (P) queryCardBinLianLianParams;
	}

	private String createSendSign(Map<String, String> param, String signKey, String signType) throws Exception {
		String result = "";
		String sb = LianlianSignUtil.getSignStr(param);
		logger.info("sb:----{}", sb);
		if ("MD5".equals(signType)) {
			// Md5签名
			sb += "&key=" + signKey;
			result = Md5Util.md5(sb);
			result = result.toLowerCase();
		} else {
			// RSA加密
			result = LianlianSignUtil.signRSA(signKey, sb);
		}

		return result;
	}

	@Override
	public <C> QueryCardBinContent transformQueryCardBinContent(C req) throws Exception {
		QueryCardBinContent queryCardBinContent = new QueryCardBinContent();

		QueryCardBinLianLianContent content = (QueryCardBinLianLianContent) req;
		if (content == null) {
			queryCardBinContent.setResultCode(PayRspCodeEnum.COMMON_ERR0R_NET_ERROR.getValue());
			return queryCardBinContent;
		}

		String retCode = content.getRet_code();
		String retMsg = content.getRet_msg();

		if (retCode.equals("0000")) { // 卡号正确-成功
			String bankCode = content.getBank_code(); // 返回银行卡编号
			String cardType = content.getCard_type();
			if ("2".equals(cardType)) {
				BankConfigPO bankConfigPO = bankConfigService.queryByThirdBankCode(PaymentEnum.LIAN_LIAN.getValue(), bankCode);
				if (bankConfigPO == null || YesNoEnum.NO.getValue().equals(bankConfigPO.getState())) {
					queryCardBinContent.setResultCode(PAY_CODE_BANK_NOT_SUPPORT.getValue());
//					queryCardBinContent.setResultMsg(retMsg);
				} else {
					queryCardBinContent.setResultCode(PayRspCodeEnum.SUCCESS.getValue());
					queryCardBinContent.setBankCode(bankConfigPO.getBankCode());
					queryCardBinContent.setEnName(bankConfigPO.getEnName());
				}

			} else {
				queryCardBinContent.setResultCode(PAY_CODE_CARD_TYPE_NOT_SUPPORT.getValue());
//				queryCardBinContent.setResultMsg("暂时只支持储蓄卡，不支持其他类型银行卡进行投资，谢谢！");
			}
		} else if (retCode.equals("5001")) {
			queryCardBinContent.setResultCode(PAY_CODE_CARD_EXCEPTION.getValue());
//			queryCardBinContent.setResultMsg("银行卡输入有误，请核对后重试，谢谢！");
		} else {
			logger.error("连连银行卡Bin查询--返回结果为：ret_code=[{}],retmsg=[{}]", retCode, retMsg);
			queryCardBinContent.setResultCode(PAY_CODE_QUERY_CARD_BIN_ERROR.getValue());
			return queryCardBinContent;
//			throw new Exception("连连银行卡Bin查询--[" + card_no + "]--返回结果为：ret_code=[" + retCode + "],retmsg=[" + retMsg + "]");
		}

		queryCardBinContent.setResultMsg(retMsg);

		queryCardBinContent.setBankName(content.getBank_name());
		logger.info(queryCardBinContent.toString());
		return queryCardBinContent;
	}

	@Override
	public <P extends Params> P transformQueryPayOutOrderParams(QueryPayoutOrderYYParams queryPayOutOrderYYParams) throws Exception {
		QueryPayOutOrderLianlianParams queryPayOutOrderLianlianParams = new QueryPayOutOrderLianlianParams();
		Map<String, String> params = new HashMap<>();
		// 请求参数
		//		try {
		queryPayOutOrderLianlianParams = getParamsPayOut(queryPayOutOrderYYParams);
		//		} catch (Throwable t) {
		//			t.printStackTrace();
		//		}
		//		String url = StringHelper.format(LianLianPayVariable.CHECK_URL.getValue(), configureProvider);	// 请求地址

		logger.info("-----------查询友金所充值订单[{}]，请求参数={}", queryPayOutOrderYYParams.getPayoutOrderId(), params);

		return (P) queryPayOutOrderLianlianParams;
	}

	/**
	 * 生成支付结果查询接口请求参数
	 *
	 * @param req
	 * @return
	 * @throws Throwable
	 */
	private QueryPayOutOrderLianlianParams getParamsPayOut(QueryPayoutOrderYYParams req) throws Exception {
		QueryPayOutOrderLianlianReq queryPayOutOrderLianlianReq = new QueryPayOutOrderLianlianReq();

		LianlianExt lianlianExt = getMerchantInfo(req.getMerchantCode(), PayTypeEnum.PAY_OUT, PayModeEnum.AUTH_PAY);
		// 连连商户号
		String oid_partner = lianlianExt.getOidPartner();
		String sign_type = lianlianExt.getSignType();        // 签名方式
		String sign_key = "MD5".equals(sign_type) ? lianlianExt.getMd5Key() : lianlianExt.getPrivateRsaKey();

		String dateStr = DateUtil.date2Str(DateUtil.str2DateTime(req.getOrderTime()), "yyyyMMddHHmmss");
		String no_order = req.getPayoutOrderId();        // 商户唯一订单号
		String dt_order = dateStr;                // 商户订单时间

		Map<String, String> params = new HashMap<String, String>();
		queryPayOutOrderLianlianReq.setOid_partner(oid_partner);
		queryPayOutOrderLianlianReq.setSign_type(sign_type);
		queryPayOutOrderLianlianReq.setNo_order(no_order);
		queryPayOutOrderLianlianReq.setDt_order(dt_order);

		// 签名
		String result = "";
		String sb = LianlianSignUtil.getSignStr(params);
		if ("MD5".equals(sign_type)) {
			// Md5签名
			sb += "&key=" + sign_key;
			result = Md5Util.md5(sb).toLowerCase();
		} else {
			// RSA加密
			result = RSAUtil.sign(sign_key, sb);
		}
		queryPayOutOrderLianlianReq.setSign(StringUtils.isBlank(result) ? "" : result);

		QueryPayOutOrderLianlianParams queryPayOutOrderLianlianParams = new QueryPayOutOrderLianlianParams();
		queryPayOutOrderLianlianParams.setUrl(lianlianExt.getCheckUrl());
		queryPayOutOrderLianlianParams.setQueryPayOutOrderLianlianReq(queryPayOutOrderLianlianReq);

		return queryPayOutOrderLianlianParams;
	}

	@Override
	public <C extends Content> QueryPayoutOrderYYContent transformQueryPayOutOrderContent(C rsp) throws Exception {
		QueryPayoutOrderYYContent queryPayoutOrderYYContent = new QueryPayoutOrderYYContent();

		QueryPayOutOrderLianlianContent queryPayOrderLianlianContent = (QueryPayOutOrderLianlianContent) rsp;

		if (queryPayOrderLianlianContent == null) {
			queryPayoutOrderYYContent.setResultCode(PayRspCodeEnum.COMMON_ERR0R_NET_ERROR.getValue());
			return queryPayoutOrderYYContent;
		}

		// 支付结果
		String result_pay = queryPayOrderLianlianContent.getResult_pay();

		if (result_pay != null) {
			switch (result_pay) {
			case "SUCCESS":
				queryPayoutOrderYYContent.setResultCode(PayRspCodeEnum.SUCCESS.getValue());
				break;
			case "FAILURE":
				queryPayoutOrderYYContent.setResultCode(PAY_CODE_QUERY_ORDER_FAIL.getValue());
				break;
			default:
				queryPayoutOrderYYContent.setResultCode(PAY_CODE_QUERY_ORDER_FAIL.getValue());
				break;
			}
			queryPayoutOrderYYContent.setOrderId(queryPayOrderLianlianContent.getNo_order());

			double moneyOrder = Double.valueOf(queryPayOrderLianlianContent.getMoney_order());
			queryPayoutOrderYYContent.setAmount(Long.valueOf(NumberUtil.yuan2fen(moneyOrder)).intValue());
			queryPayoutOrderYYContent.setResultMsg(queryPayOrderLianlianContent.getMemo());
			queryPayoutOrderYYContent.setSerialNo(queryPayOrderLianlianContent.getOid_paybill());
		} else {
			queryPayoutOrderYYContent.setResultCode(PayRspCodeEnum.PAY_CODE_QUERY_ORDER_FAIL.getValue());
			queryPayoutOrderYYContent.setResultMsg(queryPayOrderLianlianContent.getRet_msg());
		}
		return queryPayoutOrderYYContent;
	}

	@Override
	public <P extends Params> P transformWithoutVerifyParams(WithoutVerifyYYParams withoutVerifyYYParams) throws Exception {
		return null;
	}

	@Override
	public <C extends Content> WithoutVerifyYYContent transformWithoutVerifyContent(C req) throws Exception {
		return null;
	}

	private LianlianExt getMerchantInfo(String merchantCode, PayTypeEnum payType, PayModeEnum payMode) throws Exception {
		MerchantPaymentPO merchant = merchantPaymentService.queryByThirdMerchantCode(merchantCode, PaymentEnum.LIAN_LIAN.getValue(),
				payType.getValue(), payMode.getValue());

		LianlianExt lianlianExt = null;

		if (merchant == null) {
			logger.error("【lianlian】【pay】查询支付通过信息失败,商户信息为空,merchantCode:{}", merchantCode);
			throw new YYPayException(PayRspCodeEnum.PAY_CODE_PAY_FAIL.getValue(), "查询支付通过信息失败,商户信息为空.");
		}
		if (StringUtils.isNotBlank(merchant.getExt())) {
			lianlianExt = JacksonUtil.nonullMapper.fromJson(merchant.getExt(), LianlianExt.class);
		} else {
			logger.error("【lianlian】【pay】支付商户扩展信息为空,merchantCode:{}", merchantCode);
			throw new YYPayException(PayRspCodeEnum.PAY_CODE_PAY_FAIL.getValue(), "支付商户扩展信息为空");
		}
		logger.info("【lianlian】【pay】查询支付通过信息成功,merchant:{}", JacksonUtil.nonullMapper.toJson(merchant));

		return lianlianExt;
	}
}
